using System;

namespace Giraffe.Core.Common.Messengers
{
    public abstract class MessengerContact : IMessengerContact
    {
        private string id;
        protected string _name;

        public virtual event Action StateChanged;

        public MessengerContact(string id)
        {
            this.id = id;
            _name = id;
        }

        public string ID
        {
            get { return id; }
        }

        public virtual string Name
        {
            get
            {
                return _name;
            } 
            set
            {
                _name = value;
            }
        }

        public virtual string GroupName { get; set; }

        public abstract ContactStateEnum State { get; }

        public abstract MessengerType Messenger { get; }

        protected void InvokeStateChanged()
        {
            Action changed = StateChanged;
            if (changed != null) changed();
        }

        #region Equals

        public override bool Equals(object obj)
        {
            var contact = obj as MessengerContact;
            if (contact != null)
            {
                return ID.Equals(contact.ID) && Messenger.Equals(contact.Messenger);
            }
            return false;
        }

        public override int GetHashCode()
        {
            return ID.GetHashCode() + Messenger.GetHashCode();
        }

        #endregion
    }
}